package cn.guozeyiblog.blog;

import java.util.ArrayList;

import me.maxwin.view.XListView.IXListViewListener;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import cn.guozeyiblog.blog.utils.Content;
import cn.guozeyiblog.blog.utils.NetTools;
import cn.guozeyiblog.blog.utils.Statictool;

public class WitterListView  implements IXListViewListener, OnItemClickListener {
	
	private Handler handler;
	private Context context;
	private static final int WLOAD = 6;
	private static final int WUPDATE = 7;
	private static int count=1;
	private static boolean Refresh=false;
	public WitterListView(Handler h,Context c) {
		// TODO Auto-generated constructor stub
		this.context = c;
		this.handler = h;
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		
	}

	public void onRefresh() {
		// TODO Auto-generated method stub
		new Thread(){
			public void run() {
				ArrayList<Content> dataArrayList = NetTools.DoHttp(Statictool.WSIDE);
				System.err.println(Statictool.WSIDE);
				for (Content c:dataArrayList) {
					System.out.println("Title:"+c.gettitle()+"--Link:"+c.getLink());
				}		
				Message msg = new Message();
				msg.what = WUPDATE;
				msg.obj = dataArrayList;
				handler.sendMessage(msg);
			};
		}.start();
		//第一次刷新时让Count+1
		if (!Refresh) {
			count++;
		}
		Refresh = true;
	}

	@Override
	public void onLoadMore() {
		// TODO Auto-generated method stub
		new Thread(){
			public void run() {
				ArrayList<Content> dataArrayList = NetTools.DoHttp(Statictool.WSIDE+"&page="+count);
				System.err.println(Statictool.WSIDE+"&page="+count);
				for (Content c:dataArrayList) {
					System.out.println("Title:"+c.gettitle()+"--Link:"+c.getLink());
				}
				Message msg = new Message();
				msg.what = WLOAD;
				msg.obj = dataArrayList;
				handler.sendMessage(msg);
				count++;
			};
		}.start();
		
	}

}
